package controllers.administrator;

import java.util.Collection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import services.GalleryService;
import services.PaintingService;
import controllers.AbstractController;
import domain.Gallery;
import domain.Painting;

@Controller
@RequestMapping("/painting/administrator")
public class PaintingAdministratorController extends AbstractController{

	//Services
		@Autowired
		private PaintingService paintingService;

		@Autowired
		private GalleryService galleryService;
		
		//Constructor
		public PaintingAdministratorController(){
			super();
		}
		
		// Listing methods
		@RequestMapping(value = "/galleryList", method = RequestMethod.GET)
		public ModelAndView list(@RequestParam int galleryId) {
			ModelAndView result;
			Gallery gallery;
			Collection<Painting> paintings;

			gallery = galleryService.findOne(galleryId);
			paintings = paintingService.findByGallery(gallery);

			result = new ModelAndView("painting/galleryList");
			result.addObject("requestURI", "gallery/administrator/list.do");
			result.addObject("paintings", paintings);
			result.addObject("backURI", "/customer/administrator/list.do");
			return result;
		}
		
		@RequestMapping(value = "/list", method = RequestMethod.GET)
		public ModelAndView listCustomer(@RequestParam int customerId) {
			ModelAndView result;
			Collection<Painting> paintings;

			paintings = paintingService.findOwnedPaintingsByCustomerId(customerId);

			result = new ModelAndView("painting/list");
			result.addObject("requestURI", "painting/administrator/list.do");
			result.addObject("paintings", paintings);
			result.addObject("backURI", "/customer/administrator/list.do");
			return result;
		}
}
